﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbProductsExDal
	{
		public DbProductsExDal()
		{
		}
 		#region Insert
 		public static int Insert(DbProductsEx dbProductsEx)
		{	
			string sql = @"Insert Into DbProductsEx (
					PeProdCode,
					PeType,
					PeName,
					PeValue,
					PeOrder,
					PeValue0,
					PeValue1,
					PeLang,
					PeEnName
				) values('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}','{8}')";
			sql = string.Format(sql,
					SqlHelper.String(dbProductsEx.PeProdCode),
					dbProductsEx.PeType,
					dbProductsEx.PeName,
					dbProductsEx.PeValue,
					dbProductsEx.PeOrder,
					dbProductsEx.PeValue0,
					dbProductsEx.PeValue1,
					SqlHelper.String(dbProductsEx.PeLang),
					SqlHelper.String(dbProductsEx.PeEnName)
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbProductsEx dbProductsEx)
		{	
			string sql = @"Update DbProductsEx set 

					PeProdCode= '{0}',
					PeType= {1},
					PeName= '{2}',
					PeValue= '{3}',
					PeOrder= {4},
					PeValue0= '{5}',
					PeValue1= '{6}',
					PeLang= '{7}',
					PeEnName= '{8}'
				where

					PeId= {9}";
			sql = string.Format(sql,
					SqlHelper.String(dbProductsEx.PeProdCode),
					dbProductsEx.PeType,
					dbProductsEx.PeName,
					dbProductsEx.PeValue,
					dbProductsEx.PeOrder,
					dbProductsEx.PeValue0,
					dbProductsEx.PeValue1,
					SqlHelper.String(dbProductsEx.PeLang),
					SqlHelper.String(dbProductsEx.PeEnName),
					dbProductsEx.PeId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 peId)
		{
		
			string sql = @"Delete from DbProductsEx where 
					PeId= {0}";
			sql = string.Format(sql,
					peId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbProductsEx a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbProductsEx Select(Int32 peId)
		{
			DbProductsEx dbProductsEx = null;
			string sql = @"select a.* from DbProductsEx a  where
					a.PeId= {0}
";
			sql = string.Format(sql,
					peId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbProductsEx = new DbProductsEx(ds.Tables[0].Rows[0]);					
			return dbProductsEx;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbProductsEx a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbProductsEx a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbProductsEx a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
